﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using com.codebump;

public partial class IBC_IBC : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString.HasKeys())
            {
                if (Request.QueryString["listid"] != String.Empty)
                    Session["listid"] = Request.QueryString["listid"];
                else
                    Session["listid"] = 1;


                if (Request.QueryString["dnis"] != null)
                {
                    Session["dnis"] = Request.QueryString["dnis"];
                }
                else
                {
                    Session["dnis"] = "9999999999";
                }

                Session["servername"] = Request.QueryString["servername"];
                Session["projectname"] = Request.QueryString["projectname"];
                Session["campaignname"] = Request.QueryString["campaignname"];
                Session["agentid"] = Request.QueryString["agentid"];
                Session["agentfirst"] = Request.QueryString["agentfirst"];
                Session["agentlast"] = Request.QueryString["agentlast"];
                Session["commit"] = false;

                Session["App"] = new DataAccess();

                lblrConfirmationNum.Text = Session["listid"].ToString();
                lblOrderNum.Text = Session["listid"].ToString();
                //ValidateIBListID();
            }
            //The session variables are requested in the master page currently using the following syntax: Session["servername"] = Request.QueryString["servername"];
            //The page is loaded before the master page so if the code isn't in a control, it will currently error out.
            //((DataAccess)Session["App"]).ConnectInbound(Session["servername"].ToString(), Session["projectname"].ToString(), Session["campaignname"].ToString(), Session["dnis"].ToString(), Session["listid"].ToString());

            //Session["Pizza"] = "";
            Session["Oven"] = "";
            Session["ERK"] = 0;
            //Session["ERKDownsell"] = "";
            //Session["BlackReb"] = false;
            Session["CInfo"] = false;
            lblAgentName.Text = (Session["agentfirst"].ToString() + " " + Session["agentlast"].ToString()).Trim() + " ";
            WebWizard.ActiveStepIndex = 0;

            ((DataAccess)Session["App"]).PutCallData("webusercode", "J5");
            ((DataAccess)Session["App"]).CommitCallData();
            ////the following block of code specifies the years for cc expiration date validation and adds that to the error message (dynamically)
            //int yearval;
            //yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
            //rvExpYear.MinimumValue = yearval.ToString();
            //rvExpYear.ErrorMessage += "(" + yearval.ToString() + " - ";
            //rvExpYear.MaximumValue = (yearval + 10).ToString();
            //rvExpYear.ErrorMessage += (yearval + 10).ToString() + ")";
        }
        else
        {

        }


    }
    //POST LOGIC - For Step or Start pages
    //Add if statements as you add pages
    //For Next and Finish pages it is best to use the index in the if statements as below
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }

        if (page == WebWizard.WizardSteps.IndexOf(this.MainOffer))
        {
            if (ddlMainProd.SelectedIndex > 0)
            {
                ddlAddtlOvenQty_SelectedIndexChanged(null, null);
                Session["commit"] = true;
                ListItem templi = new ListItem();

                templi.Text = "Select a quantity";
                templi.Value = "0";
                ddlExtenderRingQty.Items.Clear();
                ddlCarryingCaseQty.Items.Clear();
                templi.Selected = true;
                ddlExtenderRingQty.Items.Insert(0, templi);
                ddlCarryingCaseQty.Items.Insert(0, templi);

                if (ddlMainProd.SelectedIndex == 1)
                {
                    //dynamically determines quantity of extender rings and carrying cases that can be purchased

                    for (Int32 i = 1; i <= (Convert.ToInt32(ddlMainProd.SelectedValue) + Convert.ToInt32(ddlAddtlOvenQty.SelectedValue)); i++)
                    {
                        ListItem item = new ListItem();
                        item.Text = i.ToString();
                        item.Value = i.ToString();
                        item.Selected = false;
                        ddlExtenderRingQty.Items.Add(item);
                        ddlCarryingCaseQty.Items.Add(item);
                    }
                    
                }
                else
                {
                    for (Int32 i = 1; i <= Convert.ToInt32(ddlMainProd.SelectedValue); i++)
                    {
                        ListItem item = new ListItem();
                        item.Text = i.ToString();
                        item.Value = i.ToString();
                        item.Selected = false;
                        ddlExtenderRingQty.Items.Add(item);
                        ddlCarryingCaseQty.Items.Add(item);
                    }
                }
            }
            else
            {
                ddlAddtlOvenQty.SelectedIndex = 0;
                //WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
                Session["commit"] = false;
            }
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Upsells)) //post-logic for upsell pages
        {
            if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
            {
                pnlrOnePayTotal.Visible = true;
                pnlrMultiPayTotal.Visible = false;
            }
            else
            {
                pnlrMultiPayTotal.Visible = true;
                pnlrOnePayTotal.Visible = false;
            }
            updateRecapTable();
            //buildOrder();

            //    //binds the products to the listbox

            //    //BoundField priceField = GridView1.Columns[0] as BoundField;
            //    //priceField.DataFormatString = "{0:c}";
            //    //priceField.HtmlEncode = false;
            //    BoundField desc = new BoundField();
            //    desc.DataField = "ProductDesc";
            //    desc.HeaderText = "Product Description";
            //    desc.HtmlEncode = false;
            //    BoundField Price = new BoundField();
            //    Price.DataField = "BaseRevenue";
            //    Price.HeaderText = "Per-Item Cost";
            //    Price.HtmlEncode = false;
            //    BoundField shipping = new BoundField();
            //    shipping.DataField = "SecondaryRevenue";
            //    shipping.HeaderText = "Shipping Cost Per Item";
            //    shipping.HtmlEncode = false;
            //    BoundField quantity = new BoundField();
            //    quantity.DataField = "Quantity";
            //    quantity.HeaderText = "Quantity";
            //    quantity.HtmlEncode = false;
            //    GridView1.Columns.Clear();
            //    GridView1.Columns.Add(desc);
            //    GridView1.Columns.Add(Price);
            //    GridView1.Columns.Add(shipping);
            //    GridView1.Columns.Add(quantity);
            //    GridView1.AutoGenerateColumns = false;
            //    GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //    GridView1.DataBind();

                //DataTable dtwhatever = new DataTable();
                //dtwhatever = ((DataAccess)Session["App"]).GetOrder();
                //lbProducts.DataSource = dtwhatever;

                //lbProducts.DataTextField = dtwhatever.Columns["ProductDesc"].ToString();//"ProductDesc";
                //lbProducts.DataValueField = "ProductDesc";
                ////lbProducts.DataTextField = dtwhatever.Columns["ProductDesc"].;
                ////lbProducts.DataValueField = dtwhatever.Columns["ProductDesc"].;
                //lbProducts.DataBind();
                //////Insert products here
                return;
            
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Recap))
        {
            if (ddlPaymentType.SelectedValue.ToString() == "EC")
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            }
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }
    }

    //POST LOGIC for disposition pages
    //this is for pages that contain a disposition button
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Recap))
        {

            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }


    }

    //PRE-LOGIC
    //Add if statements as needed for post-logic
    //You can use the Step ID name instead of the index as used in Next and Finish logic.
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {
        if (WebWizard.ActiveStep.Title.ToString() == "Upsells")
        {
            if (ddlMainProd.SelectedIndex <= 0)
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.MainOffer);
            }
        }
        if (WebWizard.ActiveStep.Title.ToString() == "Recap")
        {
            if (pnlrOnePayTotal.Visible)
            {
                lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");
                //lblAmount.Text = lblrOnePayTotal.Text;
                
            }
            else
            {
                lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");
                //lblAmount.Text = lblrMultiPayTotal1st.Text;
            }
            if (ddlPaymentType.SelectedItem.Value == "EC")
            {
                ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
                ((DataAccess)Session["App"]).PutCallData("RecurringTotal", "0");
            }
            else
            {
                if (cbOnePay.Checked)
                {
                    ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
                    ((DataAccess)Session["App"]).PutCallData("RecurringTotal", "0");
                }
                else
                {
                    ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrMultiPayTotal1st.Text);
                    ((DataAccess)Session["App"]).PutCallData("RecurringTotal", lblrMultiPayTotal2.Text);
                }
            }
            if (ddlPaymentType.SelectedItem.Value == "EC" && GetOrderTotalPerItemShipping() > 300.00)//Convert.ToDouble(lblrOnePayTotal.Text) > 300.00)
            {
                lblrOver300.Visible = true;
                Page.SetFocus(lblrOver300);
            }
            //((DataAccess)Session["App"]).GetOrder().Clear();
            //Oven items
            //((DataAccess)Session["App"]).PutOrderItem(129, 1); //3-pay normal
            //((DataAccess)Session["App"]).PutOrderItem(130, 1); //1-pay normal
            //((DataAccess)Session["App"]).PutOrderItem(131, 1); //$100 downsell
            //((DataAccess)Session["App"]).PutOrderItem(132, 1); //3-pay shipping discount
            //((DataAccess)Session["App"]).PutOrderItem(133, 1); //1-pay shipping discount

            //upsells and downsells
            //((DataAccess)Session["App"]).PutOrderItem(134, ddlBakingKitQty.SelectedIndex); //bakingkit
            //((DataAccess)Session["App"]).PutOrderItem(135, ddlTwistMixQty.SelectedIndex); //party mixer
            //((DataAccess)Session["App"]).PutOrderItem(136, ddlTwistMixQty.SelectedIndex); //twister free (comes with the party mixer)
            //((DataAccess)Session["App"]).PutOrderItem(137, ddlTwisterQty.SelectedIndex); //twister
            //((DataAccess)Session["App"]).PutOrderItem(138, ddlPizzaKitQty.SelectedIndex); //pizza kit
            //((DataAccess)Session["App"]).PutOrderItem(139, ddlPizzaKitQty.SelectedIndex); //pizza kit downsell
            //((DataAccess)Session["App"]).PutOrderItem(140, ddlAddtlOvenQty.SelectedIndex); //addtl oven
            //((DataAccess)Session["App"]).PutOrderItem(141, ddlExtenderRingQty.SelectedIndex); //extender ring
            //((DataAccess)Session["App"]).PutOrderItem(142, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 3-pay
            //((DataAccess)Session["App"]).PutOrderItem(143, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 1-pay
            //((DataAccess)Session["App"]).PutOrderItem(144, ddlExtenderRingQty.SelectedIndex); //extender ring free
            //((DataAccess)Session["App"]).PutOrderItem(145, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex); //black oven 3-pay
            //((DataAccess)Session["App"]).PutOrderItem(146, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex); //black oven 1-pay
            //((DataAccess)Session["App"]).PutOrderItem(147, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex); //discount black oven 3-pay
            //((DataAccess)Session["App"]).PutOrderItem(148, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex); //discount black oven 1-pay
            //((DataAccess)Session["App"]).PutOrderItem(149, ddlCarryingCaseQty.SelectedIndex); //carrying case
            //((DataAccess)Session["App"]).PutOrderItem(150, ddlMiniQty.SelectedIndex); //Mini 3-pay
            //((DataAccess)Session["App"]).PutOrderItem(151, ddlMiniQty.SelectedIndex); //Mini 1-pay
            //((DataAccess)Session["App"]).PutOrderItem(152, 1); //recipe card (24 hour processing)
            //((DataAccess)Session["App"]).PutOrderItem(153, 1); //rush shipping
            //((DataAccess)Session["App"]).PutOrderItem(154, 1); //canada surcharge
            //((DataAccess)Session["App"]).PutOrderItem(155, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex - 1); //canada surcharge addtl oven
            //((DataAccess)Session["App"]).PutOrderItem(156, 1); //alaska/hawaii surcharge
            //((DataAccess)Session["App"]).PutOrderItem(157, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex - 1); //alaska/hawaii surcharge addtl oven
            //((DataAccess)Session["App"]).PutOrderItem(158, 1); //puerto rico surcharge
            //((DataAccess)Session["App"]).PutOrderItem(159, ddlMainProdQty.SelectedIndex + ddlAddtlOvenQty.SelectedIndex - 1); //puerto rico surcharge addtl oven



        }
        if (WebWizard.ActiveStep.Title.ToString() == "Disposition")
        {

            if ((bool)Session["commit"] && (bool)Session["CInfo"])
            {
                if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
                {
                    ((DataAccess)Session["App"]).PutCallData("NumberOfRecurringPayments", "0");
                }
                else
                {
                    ((DataAccess)Session["App"]).PutCallData("NumberOfRecurringPayments", "2");
                }
                pnlDispoConfirm.Visible = false;
                ((DataAccess)Session["App"]).PutCallData("webtransfer", "");
                ((DataAccess)Session["App"]).PutCallData("webusercode", "I0");
                ((DataAccess)Session["App"]).CommitOrder();
                ((DataAccess)Session["App"]).CommitCallData();
                Response.Redirect("../DispositionComplete.aspx");
            }
            else if (!(bool)Session["commit"])
            {
                pnlDispoNonSale.Visible = true;
                pnlDispoConfirm.Visible = true;
            }
            else if (!(bool)Session["CInfo"])
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Recap);
                lblCInfoSubmitted.Visible = true;
            }
            else
            {
            }
            return;
        }
        else
        {
        }

    }

    protected void rblTwistMix_SelectedIndexChanged(object sender, EventArgs e)
    {
        Page.SetFocus(ddlMainTwistMixQty);
        if (rblTwistMix.SelectedValue == "TwisterDownsell")
        {
            lblTwistMix.Text = "How many additional Twisters would you like?";
            pnlTwister.Visible = true;
        }
        else
        {
            lblTwistMix.Text = "How many additional sets of the Party Mixer and Twister would you like?";
            pnlTwister.Visible = false;
        }
    }
    protected void btnPizzaDownsell_Click(object sender, EventArgs e)
    {
        Page.SetFocus(btnFAQ);
        pnlPizzaDownsell.Visible = true;
        btnPizzaDownsell.Visible = false;
        //Session["Pizza"] = "downsell";
    }
    protected void btnMainProdRebuttal_Click(object sender, EventArgs e)
    {
        Page.SetFocus(btnFAQ);
        if (pnlRewardCert.Visible)
        {
            pnlRewardCert.Visible = false;
            pnlHalfShipping.Visible = true;
            btnMainProdRebuttal.Visible = false;
        }
        else
        {
            pnlRewardCert.Visible = true;
            btnMainProdRebuttal.Text = "Next Rebuttal";
        }

    }
    protected void btnExtRingReb_Click(object sender, EventArgs e)
    {

        if (pnlExtenderRingDownsell1.Visible)
        {
            pnlExtenderRingDownsell1.Visible = false;
            pnlExtenderRingDownsell2.Visible = true;
            btnExtRingReb.Visible = false;
            //cbERKDown1.Checked = false;
            //Session["ERKDownsell"] = "Downsell2";
            Page.SetFocus(ddlExtenderRingQty);
        }
        else
        {
            pnlExtenderRingDownsell1.Visible = true;
            btnExtRingReb.Text = "Next Rebuttal";
            //Session["ERKDownsell"] = "Downsell1";
            Page.SetFocus(btnExtRingReb);
        }
    }
    protected void rbl24Hour_SelectedIndexChanged(object sender, EventArgs e)
    {
        Page.SetFocus(btnFAQ);
        if (rbl24Hour.SelectedValue == "No")
        {
            pnlRushShip.Visible = true;
        }
        else
        {
            pnlRushShip.Visible = false;
            cbRushShip.Checked = false;
        }
    }
    protected void btnBlackReb_Click(object sender, EventArgs e)
    {
        Page.SetFocus(cbBlackOvens);
        pnlBlackReb.Visible = true;
        btnBlackReb.Visible = false;
        //Session["BlackReb"] = true;
    }

    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        lblError.Text = "";

        bool bCustValid = false;
        bool ccCheck = false;
        bool ecCheck = false;
        bool bShipValid = false;
        bool bShowBInfo = false;
        int yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
        //int result;

        bCustValid = !(string.IsNullOrEmpty(tbFirstName.Text) ||
            string.IsNullOrEmpty(tbLastName.Text) ||
            string.IsNullOrEmpty(tbAddr.Text) ||
            (tbAddr.Text == "PO BOX ") ||
            string.IsNullOrEmpty(tbZip.Text) ||
            string.IsNullOrEmpty(ddlCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlCountry.SelectedItem.Text)) &&
            (ddlCity.SelectedIndex > 0);

        if (tbExpDate.Text.Length == 4)
        {
            ccCheck = !(string.IsNullOrEmpty(ddlCardType.SelectedItem.Text) ||
                string.IsNullOrEmpty(tbCCNumber.Text) ||
                //string.IsNullOrEmpty(tbCCV.Text) ||
                string.IsNullOrEmpty(tbExpDate.Text) ||
                (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) == yearval && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) < Convert.ToInt32(DateTime.Today.ToString("MM")))) &&
                (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) >= yearval) &&
                (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) <= (yearval + 10)) &&
                (Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) >= 1 && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) <= 12) &&
                (((DataAccess)Session["App"]).IsValidCC(GetCardType(ddlCardType.SelectedValue), tbCCNumber.Text)) &&
                //(System.Text.RegularExpressions.Regex.IsMatch(tbCCV.Text, @"^[\d]+$")) &&
                (System.Text.RegularExpressions.Regex.IsMatch(tbExpDate.Text, @"^[\d]+$"));
        }
        else
        {
            ccCheck = false;
        }

        ecCheck = !(string.IsNullOrEmpty(tbBankName.Text) ||
            string.IsNullOrEmpty(tbAccHolder.Text) ||
            string.IsNullOrEmpty(tbAccNum.Text) ||
            string.IsNullOrEmpty(tbRoutNum.Text) ||
            string.IsNullOrEmpty(tbCheckNum.Text)) &&
            (System.Text.RegularExpressions.Regex.IsMatch(tbAccNum.Text, @"^[\d]+$")) &&
            (System.Text.RegularExpressions.Regex.IsMatch(tbRoutNum.Text, @"^[\d]+$")) &&
            (System.Text.RegularExpressions.Regex.IsMatch(tbCheckNum.Text, @"^[\d]+$")) &&
            ((DataAccess)Session["App"]).ValidateRoutingNumber(Convert.ToInt32(tbRoutNum.Text));
        //(Int32.TryParse(tbAccNum.Text, out result)) &&
        //(Int32.TryParse(tbRoutNum.Text, out result)) &&
        //(Int32.TryParse(tbCheckNum.Text, out result));

        bShipValid = !(string.IsNullOrEmpty(tbShipAddr.Text) ||
            (tbShipAddr.Text == "PO BOX ") ||
            //string.IsNullOrEmpty(tbShipaddr2.Text) ||
            string.IsNullOrEmpty(tbShipZip.Text) ||
            string.IsNullOrEmpty(ddlShipCity.SelectedItem.Text) ||
            ddlShipState.Items.Count <= 0 ||
            string.IsNullOrEmpty(ddlShipState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlShipCountry.SelectedItem.Text)) &&
            (ddlShipCity.SelectedIndex > 0) &&
            (tbShipZip.Text.Length >= 5) &&
            (tbShipZip.Text.Length <= 7);

        if (!cbShipping.Checked)
        {
            if (bCustValid)
            {
                switch (ddlState.SelectedItem.Text)
                {
                    case "VI":
                    case "GU":
                    case "MP":
                    case "AS":
                    case "FM":
                    case "MH":
                    case "PW":
                    case "AA":
                    case "AE":
                    case "AP":
                    case "CZ":
                    case "PI":
                    case "TT":
                    case "CM":
                        bCustValid = false;
                        lblError.Text += "Doesn't ship to US territories (PR excluded), Guam, or the Virgin Islands<br/>";
                        break;
                }
            }
        }
        else
        {
            if (bShipValid)
            {
                switch (ddlShipState.SelectedItem.Text)
                {
                    case "VI":
                    case "GU":
                    case "MP":
                    case "AS":
                    case "FM":
                    case "MH":
                    case "PW":
                    case "AA":
                    case "AE":
                    case "AP":
                    case "CZ":
                    case "PI":
                    case "TT":
                    case "CM":
                        bShipValid = false;
                        lblError.Text += "Doesn't ship to US territories (PR excluded), Guam, or the Virgin Islands<br/>";
                        break;
                }
            }
        }

        if (bCustValid)
        {
            ((DataAccess)Session["App"]).PutCallData("firstname", tbFirstName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("lastname", tbLastName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("address1", tbAddr.Text.Replace(",", ""));
            if (!string.IsNullOrEmpty(tbAddr2.Text))
                ((DataAccess)Session["App"]).PutCallData("address2", tbAddr2.Text.Replace(",", ""));
            else
                ((DataAccess)Session["App"]).PutCallData("address2", "");
            ((DataAccess)Session["App"]).PutCallData("Zip", tbZip.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("City", ddlCity.SelectedItem.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedItem.Text);
            ((DataAccess)Session["App"]).PutCallData("Country", ddlCountry.SelectedItem.Text);

            //this is what happens if the shipping info is not visible
            if (!cbShipping.Checked)
            {
                ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text.Replace(",", ""));
                if (!string.IsNullOrEmpty(tbAddr2.Text))
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text.Replace(",", ""));
                else
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                ((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlCity.SelectedItem.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedItem.Text);
                ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedItem.Text);
            }
            //this is what happens if the shipping info is visible
            else
            {
                if (bShipValid)
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text.Replace(",", ""));
                    if (!string.IsNullOrEmpty(tbShipAddr.Text))
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbShipaddr2.Text.Replace(",", ""));
                    else
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlShipCity.SelectedItem.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedItem.Text);
                    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedItem.Text);
                }
                else
                {
                    lblError.Text += "Enter Valid Shipping Info<br/>";
                }
            }
        }
        //this else covers error checking
        else
        {
            if (tbAddr.Text == "PO BOX ")
            {
                lblError.Text += "Enter a PO BOX number <br/>";
            }
            else
            {
                if (ddlCity.Items.Count > 1 && ddlCity.SelectedIndex == 0)
                {
                    lblError.Text += "Select a City<br/>";
                }
                else
                {
                    lblError.Text += "Enter Valid Customer Data<br/>";
                }
            }
        }

        if ((!string.IsNullOrEmpty(tbPhone.Text)) && ((tbPhone.Text.Length != 10) || !(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success)))
        {
            lblError.Text += "Invalid Phone<br/>";
        }
        else
        {
            if (!string.IsNullOrEmpty(tbPhone.Text))
                ((DataAccess)Session["App"]).PutCallData("PrimaryPhone", tbPhone.Text);
        }

        if ((!string.IsNullOrEmpty(tbEmail.Text)) && !((DataAccess)Session["App"]).IsValidEmail(tbEmail.Text))
        {
            lblError.Text += "Invalid Email<br/>";
        }
        else
        {
            if (!string.IsNullOrEmpty(tbEmail.Text))
                ((DataAccess)Session["App"]).PutCallData("Email", tbEmail.Text);
        }





        if (ddlPaymentType.SelectedIndex == 1) // debit/credit
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            if (ccCheck)
            {
                ((DataAccess)Session["App"]).PutCallData("CCType", ddlCardType.SelectedItem.Value);
                ((DataAccess)Session["App"]).PutCallData("CCNumber", ((DataAccess)Session["App"]).EnryptData(tbCCNumber.Text));
                //((DataAccess)Session["App"]).PutCallData("CCV", ((DataAccess)Session["App"]).EnryptData(tbCCV.Text));
                ((DataAccess)Session["App"]).PutCallData("CCExpDate", ((DataAccess)Session["App"]).EnryptData((tbExpDate.Text.Substring(0, 2) + "/" + tbExpDate.Text.Substring(2, 2))));
                
            }
            else
            {
                lblError.Text += "Invalid Card Info<br/>";
            }
        }
        else if (ddlPaymentType.SelectedIndex == 2) // echeck
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            if (ecCheck)
            {
                ((DataAccess)Session["App"]).PutCallData("ECBankName", tbBankName.Text.Replace(",",""));
                ((DataAccess)Session["App"]).PutCallData("ECAccHolder", tbAccHolder.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ECAccNumber", tbAccNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECRoutingNumber", tbRoutNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECCheckNumber", tbCheckNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECAccType", ddlAccType.SelectedItem.Text);
            }
            else
            {
                lblError.Text += "Invalid Bank Info<br/>";
            }
        }
        else
        {
            lblError.Text += "Please select a payment method." + Environment.NewLine;
        }

        if (ddlPaymentType.SelectedValue == "EC")
        {
            pnlOnePay.Visible = false;
        }
        else
        {
            pnlOnePay.Visible = true;
        }
        if (bCustValid && (ccCheck || ecCheck))
        {
            if (!cbShipping.Checked || bShipValid)
            {
                Session["CInfo"] = true;
                lblCInfoSubmitted.Visible = false;
            }
            else
            {
                Session["CInfo"] = false;
                lblCInfoSubmitted.Visible = true;
            }
        }
        else
        {
            Session["CInfo"] = false;
            lblCInfoSubmitted.Visible = true;
        }
        lblCfirst.Text = tbFirstName.Text;
        lblCfirst1.Text = tbFirstName.Text;
        lblCfirst2.Text = tbFirstName.Text;
        if (pnlWizard.Visible)
        {
            updateRecapTable();

            lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
            lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
            lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");
                
            //buildOrder();

            ////binds the products to the listbox

            ////BoundField priceField = GridView1.Columns[0] as BoundField;
            ////priceField.DataFormatString = "{0:c}";
            ////priceField.HtmlEncode = false;
            //BoundField desc = new BoundField();
            //desc.DataField = "ProductDesc";
            //desc.HeaderText = "Product Description";
            //desc.HtmlEncode = false;
            //BoundField Price = new BoundField();
            //Price.DataField = "BaseRevenue";
            //Price.HeaderText = "Per-Item Cost";
            //Price.HtmlEncode = false;
            //BoundField shipping = new BoundField();
            //shipping.DataField = "SecondaryRevenue";
            //shipping.HeaderText = "Shipping Cost Per Item";
            //shipping.HtmlEncode = false;
            //BoundField quantity = new BoundField();
            //quantity.DataField = "Quantity";
            //quantity.HeaderText = "Quantity";
            //quantity.HtmlEncode = false;
            //GridView1.Columns.Clear();
            //GridView1.Columns.Add(desc);
            //GridView1.Columns.Add(Price);
            //GridView1.Columns.Add(shipping);
            //GridView1.Columns.Add(quantity);
            //GridView1.AutoGenerateColumns = false;
            //GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //GridView1.DataBind();
        }
        else if (pnlViewOrder.Visible)
        { 
            buildOrder();
             
            BoundField desc = new BoundField();
            desc.DataField = "ProductDesc";
            desc.HeaderText = "Product Description";
            desc.HtmlEncode = false;
            BoundField Price = new BoundField();
            Price.DataField = "BaseRevenue";
            Price.HeaderText = "Per-Item Cost";
            Price.HtmlEncode = false;
            BoundField shipping = new BoundField();
            shipping.DataField = "SecondaryRevenue";
            shipping.HeaderText = "Shipping Cost Per Item";
            shipping.HtmlEncode = false;
            BoundField quantity = new BoundField();
            quantity.DataField = "Quantity";
            quantity.HeaderText = "Quantity";
            quantity.HtmlEncode = false;
            gvViewOrder.Columns.Clear();
            gvViewOrder.Columns.Add(desc);
            gvViewOrder.Columns.Add(Price);
            gvViewOrder.Columns.Add(shipping);
            gvViewOrder.Columns.Add(quantity);
            gvViewOrder.AutoGenerateColumns = false;
            gvViewOrder.DataSource = ((DataAccess)Session["App"]).GetOrder();
            gvViewOrder.DataBind();
            lblrMultiPayTotal1st0.Text = GetOrderTotalPerItemShipping().ToString("N2");
            lblrMultiPayTotal0.Text = GetRecurringPayment().ToString("N2");
            lblrOnePayTotal0.Text = (GetOrderTotalPerItemShipping() + (2 * GetRecurringPayment())).ToString("N2");
        }

        if (ddlPaymentType.SelectedItem.Value == "EC" && GetOrderTotalPerItemShipping() > 300.00)//Convert.ToDouble(lblrOnePayTotal.Text) > 300.00)
        {
            lblrOver300.Visible = true;
            Page.SetFocus(lblrOver300);
        }
        else
        {
            lblrOver300.Visible = false;
        }
        if (ddlPaymentType.SelectedItem.Value == "EC")
        {
            lblECError.Visible = true;
            pnlECheck.Visible = true;
            bShowBInfo = true;
            ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
            ((DataAccess)Session["App"]).PutCallData("RecurringTotal","0");
        }
        else
        {
            lblECError.Visible = false;
            pnlECheck.Visible = false;
            if (cbOnePay.Checked)
            {
                ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
                ((DataAccess)Session["App"]).PutCallData("RecurringTotal", "0");
            }
            else
            {
                ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrMultiPayTotal1st.Text);
                ((DataAccess)Session["App"]).PutCallData("RecurringTotal", lblrMultiPayTotal2.Text);
            }
        }

        if (cbShipping.Checked)
        {
            if (tbShipAddr.Text.Replace(".", "").Replace(" ", "").Length >= 5)
            {
                if (tbShipAddr.Text.Replace(".", "").Replace(" ", "").Substring(0, 5).ToUpper() == "POBOX")
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text.Replace(",", "").Replace(".", ""));
                    pnlPOBOX.Visible = true;
                    bShowBInfo = true;
                }
                else
                {
                    pnlPOBOX.Visible = false;
                }
            }
        }
        else
        {
            if (tbAddr.Text.Replace(".", "").Replace(" ", "").Length >= 5)
            {
                if (tbAddr.Text.Replace(".", "").Replace(" ", "").Substring(0, 5).ToUpper() == "POBOX")
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text.Replace(",", "").Replace(".", ""));
                    ((DataAccess)Session["App"]).PutCallData("Address1", tbAddr.Text.Replace(",", "").Replace(".", ""));
                    pnlPOBOX.Visible = true;
                    bShowBInfo = true;
                }
                else
                {
                    pnlPOBOX.Visible = false;
                }
            }

        }
        if (bShowBInfo)
        {
            pnlWizard.Visible = false;
            pnlViewOrder.Visible = false;
            pnlFAQ.Visible = false;
            pnlMainReb.Visible = false;
            pnlInfo.Visible = true;
            btnViewOrder.Visible = false;
            btnSave.Visible = false;
            btnFAQ.Visible = false;
        }

        ((DataAccess)Session["App"]).CommitCallData();
        //((DataAccess)Session["App"]).PutCallData("ShippingSame", cbShipping.Checked.ToString());


        //if (cbShipping.Checked)
        //{
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbShipaddr2.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlShipCity.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedItem.Text);
        //}
        //else
        //{
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlCity.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedItem.Text);
        //}
    }

    ///***************************
    protected void ddlPaymentType_SelectedIndexChanged(object sender, EventArgs e)
    {
        pnlECheck.Visible = false;
        Session["CInfo"] = false;
        updateRecapTable();
            //buildOrder();
            //BoundField desc = new BoundField();
            //desc.DataField = "ProductDesc";
            //desc.HeaderText = "Product Description";
            //desc.HtmlEncode = false;
            //BoundField Price = new BoundField();
            //Price.DataField = "BaseRevenue";
            //Price.HeaderText = "Per-Item Cost";
            //Price.HtmlEncode = false;
            //BoundField shipping = new BoundField();
            //shipping.DataField = "SecondaryRevenue";
            //shipping.HeaderText = "Shipping Cost Per Item";
            //shipping.HtmlEncode = false;
            //BoundField quantity = new BoundField();
            //quantity.DataField = "Quantity";
            //quantity.HeaderText = "Quantity";
            //quantity.HtmlEncode = false;
            //GridView1.Columns.Clear();
            //GridView1.Columns.Add(desc);
            //GridView1.Columns.Add(Price);
            //GridView1.Columns.Add(shipping);
            //GridView1.Columns.Add(quantity);
            //GridView1.AutoGenerateColumns = false;
            //GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //GridView1.DataBind();
        lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
        lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
        lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");
        if (ddlPaymentType.SelectedValue == "CC")
        {
            trCCNumber.Visible = true;
            trCCType.Visible = true;
            trCCExpDate.Visible = true;
            //trCCV.Visible = true;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            trECAccHolder.Visible = false;
            tbAccHolder.Text = "";
            tbAccNum.Text = "";
            tbBankName.Text = "";
            tbRoutNum.Text = "";
            tbCheckNum.Text = "";
            if (cbOnePay.Checked)
            {
                pnlrOnePayTotal.Visible = true;
                pnlrMultiPayTotal.Visible = false;
            }
            else
            {
                pnlrOnePayTotal.Visible = false;
                pnlrMultiPayTotal.Visible = true;
            }

        }
        else if (ddlPaymentType.SelectedValue == "EC")
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            //trCCV.Visible = false;
            trECAccNum.Visible = true;
            trECBankName.Visible = true;
            trECCheckNum.Visible = true;
            trECRoutNum.Visible = true;
            trECAccType.Visible = true;
            trECAccHolder.Visible = true;
            pnlECheck.Visible = true;
            tbCCNumber.Text = "";
            tbExpDate.Text = "";
            pnlrOnePayTotal.Visible = true;
            pnlrMultiPayTotal.Visible = false;
        }
        else //They changed it from EC or CC to blank
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            //trCCV.Visible = false;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            tbCCNumber.Text = "";
            tbExpDate.Text = "";
            tbAccHolder.Text = "";
            tbAccNum.Text = "";
            tbBankName.Text = "";
            tbRoutNum.Text = "";
            tbCheckNum.Text = "";
            if (cbOnePay.Checked)
            {
                pnlrOnePayTotal.Visible = true;
                pnlrMultiPayTotal.Visible = false;
            }
            else
            {
                pnlrOnePayTotal.Visible = false;
                pnlrMultiPayTotal.Visible = true;
            }
        }
        

    }

    protected void cbShipping_CheckedChanged(object sender, EventArgs e)
    {
        if (cbShipping.Checked)
        {

            trShipAddr.Visible = true;
            trShipAddr2.Visible = true;
            trShipPOBoxOption.Visible = true;
            trShipCity.Visible = true;
            trShipState.Visible = true;
            trShipCountry.Visible = true;
            trShipZip.Visible = true;
            trShipLbl.Visible = true;
            trShipSearchZip.Visible = true;

        }
        else
        {
            trShipAddr.Visible = false;
            trShipAddr2.Visible = false;
            trShipPOBoxOption.Visible = false;
            trShipCity.Visible = false;
            trShipState.Visible = false;
            trShipCountry.Visible = false;
            trShipZip.Visible = false;
            trShipLbl.Visible = false;
            trShipSearchZip.Visible = false;
        }
    }

    protected void btnSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbZip.Text.ToUpper(), ddlCity, ddlState, ddlCountry);
        if (cbShipping.Checked)
        {
            if (ddlShipCountry.SelectedItem.Text == "CANADA")
            {
                ddlPaymentType.Items[2].Enabled = false;
            }
        }
        else if (ddlCountry.SelectedItem.Text == "CANADA")
        {
            ddlPaymentType.Items[2].Enabled = false;
        }
        else
        {
            ddlPaymentType.Items[2].Enabled = true;
        }
        btnSubmit_Click(null, null);
    }

    protected void btnShipSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbShipZip.Text.ToUpper(), ddlShipCity, ddlShipState, ddlShipCountry);
        if (cbShipping.Checked)
        {
            if (ddlShipCountry.SelectedItem.Text == "CANADA")
            {
                ddlPaymentType.Items[2].Enabled = false;
            }
            else
            {
                ddlPaymentType.Items[2].Enabled = true;
            }
        }
        btnSubmit_Click(null, null);
    }

    protected void ValidateZip(string strZip, DropDownList ddl_City, DropDownList ddl_State, DropDownList ddl_Country)
    {

        ddl_City.Items.Clear();
        ddl_State.Items.Clear();
        ddl_City.Enabled = true;
        ddl_State.Enabled = true;
        if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} +\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {
                com.codebump.GeoPlaces g = new com.codebump.GeoPlaces();

                com.codebump.AuthenticationHeader authHeader = new com.codebump.AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                com.codebump.GeoPlaceDistance[] places = g.GetPlacesInside(strZip, "");

                for (int i = 0; i < places.Length; i++)
                {
                    com.codebump.GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddl_City.Items.Add(li);
                }

                ddl_State.Items.Add(ddl_City.SelectedItem.Value.Split(",".ToCharArray())[0]);
                
                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddl_Country.SelectedValue = "CANADA";
                }
                else
                {
                    ddl_Country.SelectedValue = "USA";
                }

                if (ddl_City.Items.Count <= 0)
                {
                    ddl_City.Items.Add("No Cities Found");
                    ddl_State.Items.Add("No States Found");
                    ddl_City.Enabled = false;
                    ddl_State.Enabled = false;
                }
                else
                {
                    ddl_City.Items.Insert(0, "Select a City");
                    ddl_City.SelectedIndex = 0;
                    ddl_State.Enabled = false;
                }
            }
            catch
            {
                ddl_City.Items.Add("No Cities Found");
                ddl_State.Items.Add("No States Found");
                ddl_City.Enabled = false;
                ddl_State.Enabled = false;
            }
        }
        else
        {
            ddl_City.Items.Add("Invalid Zip");
            ddl_City.Enabled = false;
            ddl_State.Items.Add("Invalid Zip");
            ddl_State.Enabled = false;
        }
    }

    public DataAccess.CardType GetCardType(string cardType)
    {
        switch (cardType)
        {
            case "A":
                return DataAccess.CardType.AmericanExpress;
            case "V":
                return DataAccess.CardType.Visa;
            case "D":
                return DataAccess.CardType.Discover;
            case "M":
                return DataAccess.CardType.MasterCard;
            default:
                return DataAccess.CardType.Visa;
        }
    }
    protected void cbPOBox_CheckedChanged(object sender, EventArgs e)
    {

        tbAddr.Text = "";
        tbAddr2.Text = "";
        if (cbPOBox.Checked)
        {
            Page.SetFocus(tbAddr);
            tbAddr.Text = "PO BOX ";
            trAddr2.Visible = false;
        }
        else
        {
            trAddr2.Visible = true;
        }
    }
    protected void cbShipPOBox_CheckedChanged(object sender, EventArgs e)
    {
        tbShipAddr.Text = "";
        tbShipaddr2.Text = "";
        if (cbShipPOBox.Checked)
        {
            tbShipAddr.Text = "PO BOX ";
            trShipAddr2.Visible = false;
            Page.SetFocus(tbShipAddr);
        }
        else
        {
            trShipAddr2.Visible = true;
        }
    }

    public double GetOrderTotalPerItemShipping()
    {
        double BaseTotal = 0.00;
        double ShippingTotal = 0.00;
        for (int i = 0; i < (((DataAccess)Session["App"]).GetOrder()).Rows.Count; i++)
        {
            BaseTotal += Convert.ToDouble((Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["BaseRevenue"])) * Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["Quantity"]));
            ShippingTotal = ShippingTotal + Convert.ToDouble((Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["SecondaryRevenue"])) * Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["Quantity"]));
        }

        if (cbShipping.Checked)
        {
            if (ddlShipState.Items.Count > 0)   //error checking to make sure there is a state
            {
                if (ddlShipState.SelectedItem.Text == "IL")
                {
                    BaseTotal *= 1.07;
                }
            }
        }
        else
        {
            if (ddlState.Items.Count > 0)//error checking to make sure there is a state
            {
                if (ddlState.SelectedItem.Text == "IL")
                {
                    BaseTotal *= 1.07;
                }
            }
        }
        return Math.Round((BaseTotal + ShippingTotal), 2);
    }
    public double GetRecurringPayment()
    {
        double secTotal = 0.00;
        DataTable productscomp = new DataTable();
        for (int i = 0; i < (((DataAccess)Session["App"]).GetOrder()).Rows.Count; i++)
        {

            //productscomp = ((DataAccess)Session["App"]).GetProducts("ProductID = " + ((DataAccess)Session["App"]).GetOrder().Rows[i]["ProductID"].ToString());
            productscomp = ((DataAccess)Session["App"]).GetProducts("ProductID", ((DataAccess)Session["App"]).GetOrder().Rows[i]["ProductID"].ToString());
            if (productscomp.Rows[0]["Group2"].ToString() == "3-pay")
            {
                secTotal += Convert.ToDouble(Convert.ToDouble(((DataAccess)Session["App"]).GetOrder().Rows[i]["BaseRevenue"]) * Convert.ToDouble(((DataAccess)Session["App"]).GetOrder().Rows[i]["Quantity"]));
            }

        }

        if (cbShipping.Checked)
        {
            if (ddlShipState.Items.Count > 0) //error checking to make sure there is a state
            {
                if (ddlShipState.SelectedItem.Text == "IL")
                {
                    secTotal *= 1.07;
                }
            }
        }
        else
        {
            if (ddlState.Items.Count > 0) //error checking to make sure there is a state
            {
                if (ddlState.SelectedItem.Text == "IL")
                {
                    secTotal *= 1.07;
                }
            }
        }
        return Math.Round(secTotal, 2);
    }


    protected void ddlAddtlOvenQty_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddtlOvenQty.SelectedIndex > 0 && (ddlMainBakingKitQty.SelectedIndex > 0 || (ddlMainTwistMixQty.SelectedIndex > 0 && rblTwistMix.SelectedIndex >= 0) || ddlMainPizzaKitQty.SelectedIndex > 0))
        {
            pnlAddOvenFreebees.Visible = true;
        }
        else
        {
            pnlAddOvenFreebees.Visible = false;
        }
        //dynamically determines quantity of upsells/freebees that can be purchased
        if (ddlMainBakingKitQty.SelectedIndex > 0)
        {
            trBakingKit.Visible = true;
        }
        else
        {
            trBakingKit.Visible = false;
        }
        if (ddlMainTwistMixQty.SelectedIndex > 0 && rblTwistMix.SelectedIndex >= 0)
        {
            trTwistMix.Visible = true;
        }
        else
        {
            trTwistMix.Visible = false;
        }
        if (ddlMainPizzaKitQty.SelectedIndex > 0)
        {
            trPizzaKit.Visible = true;
        }
        else
        {
            trPizzaKit.Visible = false;
        }


        ListItem templi = new ListItem();

        templi.Text = "Select a quantity";
        templi.Value = "0";
        ddlExtenderRingQty.Items.Clear();
        ddlCarryingCaseQty.Items.Clear();
        ddladdlBakingKitQty.Items.Clear();
        ddladdlTwistMixQty.Items.Clear();
        ddladdlPizzaKitQty.Items.Clear();
        templi.Selected = true;
        ddlExtenderRingQty.Items.Insert(0, templi);
        ddlCarryingCaseQty.Items.Insert(0, templi);
        ddladdlBakingKitQty.Items.Insert(0, templi);
        ddladdlTwistMixQty.Items.Insert(0, templi);
        ddladdlPizzaKitQty.Items.Insert(0, templi);
        for (Int32 i = 1; i <= Convert.ToInt32(ddlAddtlOvenQty.SelectedValue); i++)
        {
            ListItem item = new ListItem();
            item.Text = i.ToString();
            item.Value = i.ToString();
            item.Selected = false;

            ddladdlBakingKitQty.Items.Add(item);
            ddladdlTwistMixQty.Items.Add(item);
            ddladdlPizzaKitQty.Items.Add(item);
        }
        for (Int32 i = 1; i <= (Convert.ToInt32(ddlMainProd.SelectedValue) + Convert.ToInt32(ddlAddtlOvenQty.SelectedValue)); i++)
        {
            ListItem item = new ListItem();
            item.Text = i.ToString();
            item.Value = i.ToString();
            item.Selected = false;
            ddlExtenderRingQty.Items.Add(item);
            ddlCarryingCaseQty.Items.Add(item);
        }

    }

    protected void ddlMainProd_SelectedIndexChanged(object sender, EventArgs e)
    {
        Page.SetFocus(ddlMainProd);
        if (ddlMainProd.SelectedIndex == 1)
        {
            pnlAddtlOvens.Visible = true;
        }
        else
        {
            ddlAddtlOvenQty.SelectedIndex = 0;
            ddlAddtlOvenQty_SelectedIndexChanged(null, null);
            pnlAddtlOvens.Visible = false;
        }

        ListItem templi = new ListItem();

        templi.Text = "Select a quantity";
        templi.Value = "0";
        //ddlExtenderRingQty.Items.Clear();
        //ddlCarryingCaseQty.Items.Clear();
        ddlMainBakingKitQty.Items.Clear();
        ddlMainTwistMixQty.Items.Clear();
        ddlMainPizzaKitQty.Items.Clear();
        templi.Selected = true;
        //ddlExtenderRingQty.Items.Insert(0, templi);
        //ddlCarryingCaseQty.Items.Insert(0, templi);
        ddlMainBakingKitQty.Items.Insert(0, templi);
        ddlMainTwistMixQty.Items.Insert(0, templi);
        ddlMainPizzaKitQty.Items.Insert(0, templi);
        for (Int32 i = 1; i <= Convert.ToInt32(ddlMainProd.SelectedValue); i++)
        {
            ListItem item = new ListItem();
            item.Text = i.ToString();
            item.Value = i.ToString();
            item.Selected = false;
            //ddlExtenderRingQty.Items.Add(item);
            //ddlCarryingCaseQty.Items.Add(item);
            ddlMainBakingKitQty.Items.Add(item);
            ddlMainTwistMixQty.Items.Add(item);
            ddlMainPizzaKitQty.Items.Add(item);
        }
    }


    protected void addMainProdCombos()
    {
        int mainoven = Convert.ToInt32(ddlMainProd.SelectedValue);
        int supremepizza = Convert.ToInt32(ddlMainPizzaKitQty.SelectedValue);
        int extenderring = Convert.ToInt32(Session["ERK"]);
        int addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue); //this quantity is needed to be able to add appropriate number of discounts for black oven
        //do logic for single-pay items
        if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
        {
            if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
            {
                //on the following checks, we don't care about pizza being > main b/c it will always be <= main
                //add black main, supreme pizza, ext ring combo if there are more extender rings than main ovens (ex: 2 main, 1 addtl, 3 ext)
                if (supremepizza > 0 && extenderring > 0 && mainoven > 0 && extenderring > mainoven)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(204, mainoven);

                    supremepizza -= mainoven;
                    extenderring -= mainoven;
                    mainoven -= mainoven; //0's out main ovens. No other logic should pass after this
                }
                //add black main, supreme pizza, ext ring combo if there are fewer extender rings than or the same qty of main ovens (ex: 2 main, 1 addtl, 1 ext or 2main, 2 ext)
                if (supremepizza > 0 && extenderring > 0 && mainoven > 0 && extenderring <= mainoven)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(204, extenderring);

                    supremepizza -= extenderring;
                    mainoven -= extenderring;
                    extenderring -= extenderring; //0's out the externder rings
                }

                if (mainoven > 0 && extenderring > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(186, mainoven); //black 1st plus ext ring
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(186, extenderring); //black 1st plus ext ring
                        mainoven -= extenderring;
                        extenderring -= extenderring;//0's out extring if <= main
                    }
                }
                if (mainoven > 0 && supremepizza > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(199, mainoven); //black 1st plus supreme
                    supremepizza -= mainoven;
                    mainoven -= mainoven;
                }
                if (mainoven > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(181, mainoven); //black main leftover (will be 0 if any combos are ordered)
                }
            }
            else//do logic for single-pay non-black oven combos
            {
                //add 1st, supreme pizza, ext ring combo
                if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(194, mainoven);
                        supremepizza -= mainoven;
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(194, extenderring);

                        supremepizza -= extenderring;
                        mainoven -= extenderring;
                        extenderring -= extenderring; //0's out the extender rings
                    }
                }
                
                if (mainoven > 0 && extenderring > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(176, mainoven); // 1st plus ext ring
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(176, extenderring); // 1st plus ext ring
                        mainoven -= extenderring;
                        extenderring -= extenderring;//0's out extring if <= main
                    }
                }
                if (mainoven > 0 && supremepizza > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(190, mainoven); //1st plus supreme pizza
                    supremepizza -= mainoven;
                    mainoven -= mainoven;
                }
                if (mainoven > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(171, mainoven); //leftover main oven
                }
            } //end black/non-black oven check for single-pay
        }
        else
        {
            //do logic for 3-pay items
            if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
            {
                //add black 1st, supreme pizza, ext ring combo
                if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(205, mainoven);
                        supremepizza -= mainoven;
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(205, extenderring);

                        supremepizza -= extenderring;
                        mainoven -= extenderring;
                        extenderring -= extenderring; //0's out the extender rings
                    }
                }
                if (mainoven > 0 && extenderring > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(187, mainoven); // 1st plus ext ring
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(187, extenderring); // 1st plus ext ring
                        mainoven -= extenderring;
                        extenderring -= extenderring;//0's out extring if <= main
                    }
                }
                if (mainoven > 0 && supremepizza > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(201, mainoven); //black 1st plus supreme
                    supremepizza -= mainoven;
                    mainoven -= mainoven;
                }
                if (mainoven > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(182, mainoven); //black main leftover (will be 0 if any combos are ordered)
                }
            }
            else //do logic for 3-pay non-black oven combos
            {
                //add 1st, supreme pizza, ext ring combo
                if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(196, mainoven);
                        supremepizza -= mainoven;
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(196, extenderring);

                        supremepizza -= extenderring;
                        mainoven -= extenderring;
                        extenderring -= extenderring; //0's out the extender rings
                    }
                }
                if (mainoven > 0 && extenderring > 0)
                {
                    if (extenderring > mainoven)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(178, mainoven); // 1st plus ext ring
                        extenderring -= mainoven;
                        mainoven -= mainoven; //0's out main oven
                    }
                    else
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(178, extenderring); // 1st plus ext ring
                        mainoven -= extenderring;
                        extenderring -= extenderring;//0's out extring if <= main
                    }
                }
                if (mainoven > 0 && supremepizza > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(191, mainoven); //1st plus supreme pizza
                    supremepizza -= mainoven;
                    mainoven -= mainoven;
                }
                if (mainoven > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(173, mainoven); //leftover main oven
                }
            } //end segregation check
        }//ends the if(cbonepay.checked) statement
        Session["ERK"] = extenderring;
    }
    protected void addAdditionalCombos()
    {
        if (Convert.ToInt32(ddlAddtlOvenQty.SelectedValue) > 0) //If we have addtl ovens, add combos for them.
        {
            int addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue);
            int addtlsupremepizza = Convert.ToInt32(ddladdlPizzaKitQty.SelectedValue);
            int addtlextenderring = Convert.ToInt32(Session["ERK"]);

            //do logic for single-pay items
            if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
            {
                if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
                {
                    //add black add'l, supreme pizza, ext ring combo
                    if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
                    {
                        //decrement by extenderring and put in that qty
                        if (addtlsupremepizza > addtlextenderring)
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(206, addtlextenderring);
                            addtlovens -= addtlextenderring;
                            addtlsupremepizza -= addtlextenderring;
                            addtlextenderring -= addtlextenderring;
                        }
                        //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
                        else
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(206, addtlsupremepizza);
                            addtlovens -= addtlsupremepizza;
                            addtlextenderring -= addtlsupremepizza;
                            addtlsupremepizza -= addtlsupremepizza;
                        }

                    }
                    if (addtlovens > 0 && addtlextenderring > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(188, addtlextenderring); //black addtl plus ext ring
                        addtlovens -= addtlextenderring;
                        addtlextenderring -= addtlextenderring;
                    }
                    if (addtlovens > 0 && addtlsupremepizza > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(202, addtlsupremepizza); //black addtl plus supreme
                        addtlovens -= addtlsupremepizza;
                        addtlsupremepizza -= addtlsupremepizza;
                    }
                    if (addtlovens > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(183, addtlovens); //black addtl leftover
                    }
                }
                else//do logic for single-pay non-black oven combos
                {
                    //add add'l, supreme pizza, ext ring combo
                    if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
                    {
                        //decrement by extenderring and put in that qty
                        if (addtlsupremepizza > addtlextenderring)
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(197, addtlextenderring);
                            addtlovens -= addtlextenderring;
                            addtlsupremepizza -= addtlextenderring;
                            addtlextenderring -= addtlextenderring;
                        }
                        //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
                        else
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(197, addtlsupremepizza);
                            addtlovens -= addtlsupremepizza;
                            addtlextenderring -= addtlsupremepizza;
                            addtlsupremepizza -= addtlsupremepizza;
                        }
                    }
                    if (addtlovens > 0 && addtlextenderring > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(179, addtlextenderring); // addtl plus ext ring
                        addtlovens -= addtlextenderring;
                        addtlextenderring -= addtlextenderring;
                    }
                    if (addtlovens > 0 && addtlsupremepizza > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(192, addtlsupremepizza); //addtl plus supreme pizza
                        addtlovens -= addtlsupremepizza;
                        addtlsupremepizza -= addtlsupremepizza;
                    }
                    if (addtlovens > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(174, addtlovens); //leftover addtl oven
                    }
                } //end black/non-black oven check

            }
            else
            {
                //do logic for 3-pay items
                if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
                {
                    //add black add'l, supreme pizza, ext ring combo
                    if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
                    {
                        //decrement by extenderring and put in that qty
                        if (addtlsupremepizza > addtlextenderring)
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(207, addtlextenderring);
                            addtlovens -= addtlextenderring;
                            addtlsupremepizza -= addtlextenderring;
                            addtlextenderring -= addtlextenderring;
                        }
                        //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
                        else
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(207, addtlsupremepizza);
                            addtlovens -= addtlsupremepizza;
                            addtlextenderring -= addtlsupremepizza;
                            addtlsupremepizza -= addtlsupremepizza;
                        }
                    }
                    if (addtlovens > 0 && addtlextenderring > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(189, addtlextenderring); //black addtl plus ext ring
                        addtlovens -= addtlextenderring;
                        addtlextenderring -= addtlextenderring;
                    }
                    if (addtlovens > 0 && addtlsupremepizza > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(203, addtlsupremepizza); //black addtl plus supreme
                        addtlovens -= addtlsupremepizza;
                        addtlsupremepizza -= addtlsupremepizza;
                    }
                    if (addtlovens > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(185, addtlovens); //black addtl leftover
                    }
                }
                else //do logic for 3-pay non-black oven combos
                {
                    //add add'l, supreme pizza, ext ring combo
                    if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
                    {
                        //decrement by extenderring and put in that qty
                        if (addtlsupremepizza > addtlextenderring)
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(198, addtlextenderring);
                            addtlovens -= addtlextenderring;
                            addtlsupremepizza -= addtlextenderring;
                            addtlextenderring -= addtlextenderring;
                        }
                        //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
                        else
                        {
                            ((DataAccess)Session["App"]).PutOrderItem(198, addtlsupremepizza);
                            addtlovens -= addtlsupremepizza;
                            addtlextenderring -= addtlsupremepizza;
                            addtlsupremepizza -= addtlsupremepizza;
                        }
                    }
                    if (addtlovens > 0 && addtlextenderring > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(180, addtlextenderring); // addtl plus ext ring
                        addtlovens -= addtlextenderring;
                        addtlextenderring -= addtlextenderring;
                    }
                    if (addtlovens > 0 && addtlsupremepizza > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(193, addtlsupremepizza); //addtl plus supreme pizza
                        addtlovens -= addtlsupremepizza;
                        addtlsupremepizza -= addtlsupremepizza;
                    }
                    if (addtlovens > 0)
                    {
                        ((DataAccess)Session["App"]).PutOrderItem(175, addtlovens); //leftover addtl oven
                    }

                } //end segregation check
            }//ends the if(cbonepay.checked) statement
        } //ends check for additional ovens
    }
    protected void addUpsellFreebie(bool mini)
    {
        int mainoven = Convert.ToInt32(ddlMainProd.SelectedValue);
        int addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue);

        //add non-combo upsells/freebies
        if ((ddlMainBakingKitQty.SelectedIndex + ddladdlBakingKitQty.SelectedIndex) > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(229, (ddlMainBakingKitQty.SelectedIndex + ddladdlBakingKitQty.SelectedIndex)); //baking kit
        }
        if (rblTwistMix.SelectedIndex == 0 && (ddlMainTwistMixQty.SelectedIndex + ddladdlTwistMixQty.SelectedIndex) > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(227, (ddlMainTwistMixQty.SelectedIndex + ddladdlTwistMixQty.SelectedIndex)); //party mixer
            ((DataAccess)Session["App"]).PutOrderItem(228, (ddlMainTwistMixQty.SelectedIndex + ddladdlTwistMixQty.SelectedIndex)); //twister free (comes with the party mixer)
        }
        if (rblTwistMix.SelectedIndex == 1 && (ddlMainTwistMixQty.SelectedIndex + ddladdlTwistMixQty.SelectedIndex) > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(224, (ddlMainTwistMixQty.SelectedIndex + ddladdlTwistMixQty.SelectedIndex)); //twister
        }
        //do logic for single-pay items
        if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
        {
            if (mini)
            {
                ((DataAccess)Session["App"]).PutOrderItem(210, ddlMiniQty.SelectedIndex); //add single pay mini oven to order
            }
            if (ddlCarryingCaseQty.SelectedIndex > 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(208, ddlCarryingCaseQty.SelectedIndex); //add 1-pay carrying case
            }
            if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
            {
                if (cbBlackDwn.Checked)// Convert.ToBoolean(Session["BlackReb"]))//check to see if we need to give the discounted price for black ovens
                {
                    ((DataAccess)Session["App"]).PutOrderItem(237, mainoven + addtlovens); //add black oven discount 1-pay
                }
            }
            if (cbERKDown2.Checked && ddlExtenderRingQty.SelectedIndex > 0)// Session["ERKDownsell"].ToString() == "Downsell2")
            {
                ((DataAccess)Session["App"]).PutOrderItem(230, ddlExtenderRingQty.SelectedIndex); //extender ring free
            }
            else if (cbERKDown1.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell1")
            {
                ((DataAccess)Session["App"]).PutOrderItem(232, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 1-pay
            }
        }
        else
        {
            if (mini)
            {
                ((DataAccess)Session["App"]).PutOrderItem(211, ddlMiniQty.SelectedIndex); //add 3-pay mini oven to order
            }
            if (ddlCarryingCaseQty.SelectedIndex != 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(209, ddlCarryingCaseQty.SelectedIndex); //add 3-pay carrying case
            }
            if (cbBlackOvens.Checked)
            {
                if (cbBlackDwn.Checked)// Convert.ToBoolean(Session["BlackReb"]))//check to see if we need to give the discounted price for black ovens
                {
                    ((DataAccess)Session["App"]).PutOrderItem(238, mainoven + addtlovens); //add black oven discount 3-pay
                }
            }
            if (cbERKDown2.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell2")
            {
                ((DataAccess)Session["App"]).PutOrderItem(231, ddlExtenderRingQty.SelectedIndex); //extender ring free
            }
            else if (cbERKDown1.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell1")
            {
                ((DataAccess)Session["App"]).PutOrderItem(233, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 3-pay
            }
        }
    }
    protected void addSurchargeShipping(bool mini)
    {
        if (cbShipping.Checked) //if shipping info is visible
        {
            if (ddlShipState.Items.Count <= 0)//error checking to make sure that there is a state selected.
            {
                lblError.Text = "Please enter a valid shipping zip code";
                lblError.Visible = true;
                return;
            }
            if (ddlAddtlOvenQty.SelectedIndex > 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //discount for additional ovens
            }
            if (ddlShipCountry.SelectedValue == "CANADA") //if shipping country is canada
            {
                ((DataAccess)Session["App"]).PutOrderItem(212, Convert.ToInt32(ddlMainProd.SelectedValue)); //canada surcharge for initial oven

                if (cbHalfShip.Checked)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                else
                {
                    if (cbRewardCert.Checked)
                    {
                        ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    }
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(213, ddlAddtlOvenQty.SelectedIndex); //canada surcharge addtl oven
                }
                if (cbRushShip.Checked)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(221, 1); //canada rush shipping
                    ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
                }
                if (mini)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(219, ddlMiniQty.SelectedIndex); //add surcharge for mini's outside of continental 48 states based on shipping city
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if canada
                }
                
            }
            else
            {
                if (cbRushShip.Checked)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(220, 1); //US rush shipping
                    ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
                }
            }
            if (ddlShipState.SelectedItem.Text == "PR")
            {
                ((DataAccess)Session["App"]).PutOrderItem(217, ddlMainProd.SelectedIndex); //puerto rico surcharge
                
                if (cbHalfShip.Checked)
                {
                    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                else
                {
                    if (cbRewardCert.Checked)
                    {
                        //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    }
                }
                if ((1 + ddlAddtlOvenQty.SelectedIndex - 1) > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(218, ddlAddtlOvenQty.SelectedIndex); //puerto rico surcharge addtl oven
                }
                if (mini)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(219, ddlMiniQty.SelectedIndex); //add surcharge for mini's outside of continental 48 states based on shipping city
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if PR
                }
               
            }
            if (ddlShipState.SelectedItem.Text == "AK" || ddlShipState.SelectedItem.Text == "HI")
            {
                ((DataAccess)Session["App"]).PutOrderItem(214, ddlMainProd.SelectedIndex); //alaska/hawaii surcharge
                
                if (cbHalfShip.Checked)
                {
                    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                else
                {
                    //if (cbRewardCert.Checked)
                    //{
                    //    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    //}
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(216, ddlAddtlOvenQty.SelectedIndex); //alaska/hawaii surcharge addtl oven
                }
                if (mini)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(219, ddlMiniQty.SelectedIndex); //add surcharge for mini's outside of continental 48 states based on shipping city
                }
                
            }
            if (ddlShipState.SelectedItem.Text == "CT" || ddlShipState.SelectedItem.Text == "RI")
            {
                ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if CT or RI
            }
        }
        else
        {
            if (ddlState.Items.Count <= 0)  //error checking to make sure that there is a state selected.
            {
                lblError.Text = "Please enter a valid zip code";
                lblError.Visible = true;
                return;
            }
            if (ddlAddtlOvenQty.SelectedIndex > 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //discount for additional ovens
            }
            if (ddlCountry.SelectedValue == "CANADA")
            {
                ((DataAccess)Session["App"]).PutOrderItem(212, ddlMainProd.SelectedIndex); //canada surcharge

                if (cbHalfShip.Checked)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                else
                {
                    if (cbRewardCert.Checked)
                    {
                        ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    }
                }
                if ((1 + ddlAddtlOvenQty.SelectedIndex - 1) > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(213, ddlAddtlOvenQty.SelectedIndex); //canada surcharge addtl oven
                }
                if (cbRushShip.Checked)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(221, 1); //canada rush shipping
                    ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if canada
                }
                if (mini)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(219, ddlMiniQty.SelectedIndex); //add surcharge for mini's outside of continental 48 states based on shipping city
                }
                
            }
            else
            {
                if (cbRushShip.Checked)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(220, 1); //US rush shipping
                    ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
                }
            }
            if (ddlState.SelectedItem.Text == "PR")
            {
                ((DataAccess)Session["App"]).PutOrderItem(217, ddlMainProd.SelectedIndex); //puerto rico surcharge

                if (cbHalfShip.Checked)
                {
                    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                else
                {
                    if (cbRewardCert.Checked)
                    {
                        //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    }
                }
                if ((ddlAddtlOvenQty.SelectedIndex) > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(218, ddlAddtlOvenQty.SelectedIndex); //puerto rico surcharge addtl oven
                }
                if (mini)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(219, ddlMiniQty.SelectedIndex); //add surcharge for mini's outside of continental 48 states based on shipping city
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if PR
                }
                
            }
            if (ddlState.SelectedItem.Text == "AK" || ddlState.SelectedItem.Text == "HI")
            {
                ((DataAccess)Session["App"]).PutOrderItem(214, ddlMainProd.SelectedIndex); //alaska/hawaii surcharge
                
                if (cbHalfShip.Checked)
                {
                    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                else
                {
                    if (cbRewardCert.Checked)
                    {
                        //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    }
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(216, ddlAddtlOvenQty.SelectedIndex); //alaska/hawaii surcharge addtl oven
                }
                if (mini)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(219, ddlMiniQty.SelectedIndex); //add surcharge for mini's outside of continental 48 states based on shipping city
                }
                
            }
            if (ddlState.SelectedItem.Text == "CT" || ddlState.SelectedItem.Text == "RI")
            {
                ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if CT or RI
            }
        }
    }
    protected void buildOrder()
    {
        ((DataAccess)Session["App"]).GetOrder().Rows.Clear();
        if (Convert.ToInt32(ddlMainProd.SelectedValue) > 0) //This if statement is just a failsafe in case they are somehow able to get to the upsell page without having any ovens ordered
        {

            Session["ERK"] = ddlExtenderRingQty.SelectedValue;
            Boolean mini = false;
            if (ddlMiniQty.SelectedIndex > 0)
            {
                mini = true;
            }
            //get quantities for products
            //the principle behind this whole mess is that all upsells/downsells will be <= mainoven qty + addtloven qty
            //NOTE: decremented by qty needs to be last when decrementing fields so it's not 0'ed before decrement
            addMainProdCombos();
            addAdditionalCombos();
            addUpsellFreebie(mini);

            //add stuff that's free with every order
            ((DataAccess)Session["App"]).PutOrderItem(225, 1); //warranty, dvd, recipe
            ((DataAccess)Session["App"]).PutOrderItem(226, 1); //Free memberhsip to nuwave cooking club

            //add next day processing
            if (rbl24Hour.SelectedIndex == 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(222, 1); //24 hour processing
                ((DataAccess)Session["App"]).PutCallData("NextDayShip", "1");
            }
            else
            {
                ((DataAccess)Session["App"]).PutCallData("NextDayShip", "0");
            }

            //add discounts
            if (ddlMainPizzaKitQty.SelectedIndex > 0 && cbPKDown.Checked)// Session["Pizza"].ToString() == "downsell")
            {
                ((DataAccess)Session["App"]).PutOrderItem(234, 1); //pizza discount for first kit
            }

            if (cbHalfShip.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(223, 1); //$100 downsell
                ((DataAccess)Session["App"]).PutOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
            }
            else
            {
                if (cbRewardCert.Checked)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(223, 1); //$100 downsell
                }
            }
            addSurchargeShipping(mini);
            //if (cbOnePay.Visible == false || cbOnePay.Checked)
            //{
            //    //******************add recipe card thing
            //    //((DataAccess)Session["App"]).PutOrderItem(152, 1); //recipe card for single pay
            //}
        }
    }
    protected void btnFAQ_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        btnViewOrder.Text = "View Order";
        btnSave.Text = "Save the Sale Rebuttals";
        pnlWizard.Visible = false;
        pnlMainReb.Visible = false;
        pnlViewOrder.Visible = false;

        if (pnlFAQ.Visible)
        {
            pnlFAQ.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlFAQ.Visible = true;
            btnFAQ.Text = "Return to Script";
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        btnViewOrder.Text = "View Order";
        btnSave.Text = "Save the Sale Rebuttals";
        pnlWizard.Visible = false;
        pnlFAQ.Visible = false;
        pnlViewOrder.Visible = false;

        if (pnlMainReb.Visible)
        {
            pnlMainReb.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlMainReb.Visible = true;
            btnSave.Text = "Return to Script";
        }
        if (pnlWizard.Visible)
        {
            updateRecapTable();
            //buildOrder();
            //BoundField desc = new BoundField();
            //desc.DataField = "ProductDesc";
            //desc.HeaderText = "Product Description";
            //desc.HtmlEncode = false;
            //BoundField Price = new BoundField();
            //Price.DataField = "BaseRevenue";
            //Price.HeaderText = "Per-Item Cost";
            //Price.HtmlEncode = false;
            //BoundField shipping = new BoundField();
            //shipping.DataField = "SecondaryRevenue";
            //shipping.HeaderText = "Shipping Cost Per Item";
            //shipping.HtmlEncode = false;
            //BoundField quantity = new BoundField();
            //quantity.DataField = "Quantity";
            //quantity.HeaderText = "Quantity";
            //quantity.HtmlEncode = false;
            //GridView1.Columns.Clear();
            //GridView1.Columns.Add(desc);
            //GridView1.Columns.Add(Price);
            //GridView1.Columns.Add(shipping);
            //GridView1.Columns.Add(quantity);
            //GridView1.AutoGenerateColumns = false;
            //GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //GridView1.DataBind();
        }
    }
    protected void btnViewOrder_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        btnViewOrder.Text = "View Order";
        btnSave.Text = "Save the Sale Rebuttals";
        pnlWizard.Visible = false;
        pnlFAQ.Visible = false;
        pnlMainReb.Visible = false;

        if (pnlViewOrder.Visible)
        {
            pnlViewOrder.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlViewOrder.Visible = true;
            btnViewOrder.Text = "Return to Script";
        }
        buildOrder();
        
        BoundField desc = new BoundField();
        desc.DataField = "ProductDesc";
        desc.HeaderText = "Product Description";
        desc.HtmlEncode = false;
        BoundField Price = new BoundField();
        Price.DataField = "BaseRevenue";
        Price.HeaderText = "Per-Item Cost";
        Price.HtmlEncode = false;
        BoundField shipping = new BoundField();
        shipping.DataField = "SecondaryRevenue";
        shipping.HeaderText = "Shipping Cost Per Item";
        shipping.HtmlEncode = false;
        BoundField quantity = new BoundField();
        quantity.DataField = "Quantity";
        quantity.HeaderText = "Quantity";
        quantity.HtmlEncode = false;
        gvViewOrder.Columns.Clear();
        gvViewOrder.Columns.Add(desc);
        gvViewOrder.Columns.Add(Price);
        gvViewOrder.Columns.Add(shipping);
        gvViewOrder.Columns.Add(quantity);
        gvViewOrder.AutoGenerateColumns = false;
        gvViewOrder.DataSource = ((DataAccess)Session["App"]).GetOrder();
        gvViewOrder.DataBind();
        lblrMultiPayTotal1st0.Text = GetOrderTotalPerItemShipping().ToString("N2");
        lblrMultiPayTotal0.Text = GetRecurringPayment().ToString("N2");
        lblrOnePayTotal0.Text = (GetOrderTotalPerItemShipping() + (2 * GetRecurringPayment())).ToString("N2");
        if (ddlPaymentType.SelectedValue == "EC")
        {
            lblECError.Visible = true;
        }
        else
        {
            lblECError.Visible = false;
        }
    }
    protected void btnInfoDone_Click(object sender, EventArgs e)
    {
        pnlInfo.Visible = false;
        pnlWizard.Visible = true;
        btnFAQ.Visible = true;
        btnViewOrder.Visible = true;
        btnSave.Visible = true;
    }
    protected void updateRecapTable()
    {
        buildOrder();
        BoundField desc = new BoundField();
        desc.DataField = "ProductDesc";
        desc.HeaderText = "Product Description";
        desc.HtmlEncode = false;
        BoundField Price = new BoundField();
        Price.DataField = "BaseRevenue";
        Price.HeaderText = "Per-Item Cost";
        Price.HtmlEncode = false;
        BoundField shipping = new BoundField();
        shipping.DataField = "SecondaryRevenue";
        shipping.HeaderText = "Shipping Cost Per Item";
        shipping.HtmlEncode = false;
        BoundField quantity = new BoundField();
        quantity.DataField = "Quantity";
        quantity.HeaderText = "Quantity";
        quantity.HtmlEncode = false;
        GridView1.Columns.Clear();
        GridView1.Columns.Add(desc);
        GridView1.Columns.Add(Price);
        GridView1.Columns.Add(shipping);
        GridView1.Columns.Add(quantity);
        GridView1.AutoGenerateColumns = false;
        GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
        GridView1.DataBind();
    }
}
/////////////BACKUP OF PRODUCT ADDITION LOGIC
    //((DataAccess)Session["App"]).GetOrder().Rows.Clear();
    //        if (cbMainProd.Checked)
    //        {
    //            //get quantities for products
    //            //the principle behind this whole mess is that all upsells/downsells will be <= mainoven qty + addtloven qty
    //            //NOTE: decremented by qty needs to be last when decrementing fields so it's not 0'ed before decrement
    //            int mainoven = 1;
    //            int addtlovens;
    //            int supremepizza;
    //            int extenderring;
    //            if (cbAddtlOven.Checked)
    //            {
    //                addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue);
    //            }
    //            else
    //            {
    //                addtlovens = 0;
    //            }
    //            if (cbExtenderRing.Checked)
    //            {
    //                extenderring = Convert.ToInt32(ddlExtenderRingQty.SelectedValue);
    //            }
    //            else
    //            {
    //                extenderring = 0;
    //            }
    //            //checks to make sure they want the pizza kit on the order. Do this because default > 0;
    //            if (cbPizzaKit.Checked)
    //            {
    //                supremepizza = Convert.ToInt32(ddladdlPizzaKitQty.SelectedValue);
    //            }
    //            else
    //            {
    //                supremepizza = 0;
    //            }
    //            Boolean mini = false;
    //            if (cbMini.Checked && ddlMiniQty.SelectedIndex > 0)
    //            {
    //                mini = true;
    //            }
    //            //do logic for single-pay items
    //            if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
    //            {
    //                if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
    //                {
    //                    if (pnlBlackReb.Visible)//check to see if we need to give the discounted price for black ovens
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(237, mainoven + addtlovens);
    //                    }
    //                    //add black 1st, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(204, 1);

    //                        supremepizza -= mainoven;
    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    //add black add'l, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && addtlovens > 0)
    //                    {
    //                        //make sure that there are more addtl ovens left than either upsell
    //                        if (addtlovens > supremepizza && addtlovens > extenderring)
    //                        {
    //                            //decrement by extenderring and put in that qty
    //                            if (supremepizza > extenderring)
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(206, extenderring);
    //                                addtlovens -= extenderring;
    //                                supremepizza -= extenderring;
    //                                extenderring -= extenderring;
    //                            }
    //                            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
    //                            else
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(206, supremepizza);
    //                                addtlovens -= supremepizza;
    //                                extenderring -= supremepizza;
    //                                supremepizza -= supremepizza;
    //                            }
    //                        }
    //                        else
    //                        {
    //                            //put in qty based on addtl ovens
    //                            ((DataAccess)Session["App"]).PutOrderItem(206, addtlovens);

    //                            supremepizza -= addtlovens;
    //                            extenderring -= addtlovens;
    //                            addtlovens -= addtlovens;
    //                        }

    //                    }
    //                    if (mainoven > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(186, mainoven); //black 1st plus ext ring

    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(188, extenderring); //black addtl plus ext ring
    //                        addtlovens -= extenderring;
    //                        extenderring -= extenderring;
    //                    }
    //                    if (mainoven > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(199, mainoven); //black 1st plus supreme
    //                        supremepizza -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(202, supremepizza); //black addtl plus supreme
    //                        addtlovens -= supremepizza;
    //                        supremepizza -= supremepizza;
    //                    }
    //                    if (mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(181, mainoven); //black main leftover (will be 0 if any combos are ordered)
    //                    }
    //                    if (addtlovens > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(183, addtlovens); //black addtl leftover
    //                    }
    //                }
    //                else//do logic for single-pay non-black oven combos
    //                {
    //                    //add 1st, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(194, mainoven);
    //                        supremepizza -= mainoven;
    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    //add add'l, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && addtlovens > 0)
    //                    {
    //                        //make sure that there are more addtl ovens left than either upsell
    //                        if (addtlovens > supremepizza && addtlovens > extenderring)
    //                        {
    //                            //decrement by extenderring and put in that qty
    //                            if (supremepizza > extenderring)
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(197, extenderring);
    //                                addtlovens -= extenderring;
    //                                supremepizza -= extenderring;
    //                                extenderring -= extenderring;
    //                            }
    //                            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
    //                            else
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(197, supremepizza);
    //                                addtlovens -= supremepizza;
    //                                extenderring -= supremepizza;
    //                                supremepizza -= supremepizza;
    //                            }
    //                        }
    //                        else
    //                        {
    //                            //put in qty based on addtl ovens
    //                            ((DataAccess)Session["App"]).PutOrderItem(197, addtlovens);

    //                            supremepizza -= addtlovens;
    //                            extenderring -= addtlovens;
    //                            addtlovens -= addtlovens;
    //                        }

    //                    }
    //                    if (mainoven > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(176, mainoven); // 1st plus ext ring
    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(179, extenderring); // addtl plus ext ring
    //                        addtlovens -= extenderring;
    //                        extenderring -= extenderring;
    //                    }
    //                    if (mainoven > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(190, mainoven); //1st plus supreme pizza
    //                        supremepizza -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(192, supremepizza); //addtl plus supreme pizza
    //                        addtlovens -= supremepizza;
    //                        supremepizza -= supremepizza;
    //                    }
    //                    if (mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(171, mainoven); //leftover main oven
    //                    }
    //                    if (addtlovens > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(174, addtlovens); //leftover addtl oven
    //                    }
    //                } //end black/non-black oven check
    //                if (mini)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(210, ddlMiniQty.SelectedIndex); //add single pay mini oven to order
    //                }
    //                if (cbCarryingCase.Checked && ddlCarryingCaseQty.SelectedIndex != 0)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(208, ddlCarryingCaseQty.SelectedIndex); //add 1-pay carrying case
    //                }
    //                if (pnlExtenderRingDownsell2.Visible)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(230, ddlExtenderRingQty.SelectedIndex); //extender ring free
    //                }
    //                else if (pnlExtenderRingDownsell1.Visible)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(232, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 1-pay
    //                }
    //            }
    //            else
    //            {
    //                //do logic for 3-pay items
    //                if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
    //                {
    //                    if (pnlBlackReb.Visible)//check to see if we need to give the discounted price for black ovens
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(238, mainoven + addtlovens);
    //                    }
    //                    //add black 1st, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(205, 1);

    //                        supremepizza -= mainoven;
    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    //add black add'l, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && addtlovens > 0)
    //                    {
    //                        //make sure that there are more addtl ovens left than either upsell
    //                        if (addtlovens > supremepizza && addtlovens > extenderring)
    //                        {
    //                            //decrement by extenderring and put in that qty
    //                            if (supremepizza > extenderring)
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(207, extenderring);
    //                                addtlovens -= extenderring;
    //                                supremepizza -= extenderring;
    //                                extenderring -= extenderring;
    //                            }
    //                            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
    //                            else
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(207, supremepizza);
    //                                addtlovens -= supremepizza;
    //                                extenderring -= supremepizza;
    //                                supremepizza -= supremepizza;
    //                            }
    //                        }
    //                        else
    //                        {
    //                            //put in qty based on addtl ovens
    //                            ((DataAccess)Session["App"]).PutOrderItem(207, addtlovens);

    //                            supremepizza -= addtlovens;
    //                            extenderring -= addtlovens;
    //                            addtlovens -= addtlovens;
    //                        }

    //                    }
    //                    if (mainoven > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(187, mainoven); //black 1st plus ext ring

    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(189, extenderring); //black addtl plus ext ring
    //                        addtlovens -= extenderring;
    //                        extenderring -= extenderring;
    //                    }
    //                    if (mainoven > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(201, mainoven); //black 1st plus supreme
    //                        supremepizza -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(203, supremepizza); //black addtl plus supreme
    //                        addtlovens -= supremepizza;
    //                        supremepizza -= supremepizza;
    //                    }
    //                    if (mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(182, mainoven); //black main leftover (will be 0 if any combos are ordered)
    //                    }
    //                    if (addtlovens > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(185, addtlovens); //black addtl leftover
    //                    }
    //                }
    //                else //do logic for 3-pay non-black oven combos
    //                {
    //                    //add 1st, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(196, mainoven);
    //                        supremepizza -= mainoven;
    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    //add add'l, supreme pizza, ext ring combo
    //                    if (supremepizza > 0 && extenderring > 0 && addtlovens > 0)
    //                    {
    //                        //make sure that there are more addtl ovens left than either upsell
    //                        if (addtlovens > supremepizza && addtlovens > extenderring)
    //                        {
    //                            //decrement by extenderring and put in that qty
    //                            if (supremepizza > extenderring)
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(198, extenderring);
    //                                addtlovens -= extenderring;
    //                                supremepizza -= extenderring;
    //                                extenderring -= extenderring;
    //                            }
    //                            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
    //                            else
    //                            {
    //                                ((DataAccess)Session["App"]).PutOrderItem(198, supremepizza);
    //                                addtlovens -= supremepizza;
    //                                extenderring -= supremepizza;
    //                                supremepizza -= supremepizza;
    //                            }
    //                        }
    //                        else
    //                        {
    //                            //put in qty based on addtl ovens
    //                            ((DataAccess)Session["App"]).PutOrderItem(198, addtlovens);

    //                            supremepizza -= addtlovens;
    //                            extenderring -= addtlovens;
    //                            addtlovens -= addtlovens;
    //                        }

    //                    }
    //                    if (mainoven > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(178, mainoven); // 1st plus ext ring
    //                        extenderring -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && extenderring > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(180, extenderring); // addtl plus ext ring
    //                        addtlovens -= extenderring;
    //                        extenderring -= extenderring;
    //                    }
    //                    if (mainoven > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(191, mainoven); //1st plus supreme pizza
    //                        supremepizza -= mainoven;
    //                        mainoven -= mainoven;
    //                    }
    //                    if (addtlovens > 0 && supremepizza > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(193, supremepizza); //addtl plus supreme pizza
    //                        addtlovens -= supremepizza;
    //                        supremepizza -= supremepizza;
    //                    }
    //                    if (mainoven > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(173, mainoven); //leftover main oven
    //                    }
    //                    if (addtlovens > 0)
    //                    {
    //                        ((DataAccess)Session["App"]).PutOrderItem(175, addtlovens); //leftover addtl oven
    //                    }

    //                } //end segregation check
    //                if (mini)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(211, ddlMiniQty.SelectedIndex); //add 3-pay mini oven to order
    //                }
    //                if (cbCarryingCase.Checked && ddlCarryingCaseQty.SelectedIndex != 0)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(209, ddlCarryingCaseQty.SelectedIndex); //add 3-pay carrying case
    //                }
    //                if (pnlExtenderRingDownsell2.Visible)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(231, ddlExtenderRingQty.SelectedIndex); //extender ring free
    //                }
    //                else if (pnlExtenderRingDownsell1.Visible)
    //                {
    //                    ((DataAccess)Session["App"]).PutOrderItem(233, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 3-pay
    //                }
    //            }//ends the if(cbonepay.checked) statement
